package tests;

import common.Utils;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;

import java.io.IOException;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User:DELL
 * Date:2025-03-29
 * Time:19:19
 */
public class ContactPage extends Utils {
    public static String url="http://127.0.0.1:8080/client.html";
    public ContactPage() {
        super(url);
    }


    public void ContactPageRight() throws InterruptedException, IOException {
        //点击联系人列表
        driver.findElement(By.cssSelector("body > div.client-container > div > div.left > div.tab > div.tab-friend")).click();
        Thread.sleep(3000);
        //遍历联系人列表
        List<WebElement> nums=driver.findElements(By.cssSelector("#friend-list"));
        if(nums.size()!= 0){
            String name= driver.findElement(By.cssSelector("#friend-list > li:nth-child(1) > h4")).getText();
            Thread.sleep(3000);
            //点击置顶联系人
            driver.findElement(By.cssSelector("#friend-list > li:nth-child(1) > h4")).click();
            Thread.sleep(3000);
            //点击具体会话
            driver.findElement(By.cssSelector("#session-list > li:nth-child(1)>h3")).click();
            Thread.sleep(3000);
            //检查消息和用户名
            String text=driver.findElement(By.cssSelector("body > div.client-container > div > div.right > div.message-show > div.message.message-right > div > p")).getText();
            String nameA=driver.findElement(By.cssSelector("body > div.client-container > div > div.right > div.message-show > div.message.message-right > div > h4")).getText();
            //验证最新一条消息
            assert text.equals("你好呀！");
            getScreenShot(getClass().getName());
            Thread.sleep(3000);
        }
    }
}
